package com.atguigu.crowd.mvc.handler;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.entity.Student;
import com.atguigu.crowd.service.api.AdminService;
import com.atguigu.crowd.util.CrowdUtil;
import com.atguigu.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class test {
    @Autowired
    AdminService adminService;


    @RequestMapping("/test.html")
    public String tt(Model model, HttpServletRequest httpServletRequest){
        boolean judgeResult = CrowdUtil.judgeRequestType(httpServletRequest);
        System.out.println(judgeResult);
        List<Admin> admin = adminService.getAdmin();
        model.addAttribute("admin",admin);
        System.out.println(admin);
        return "target";
    }


    @ResponseBody
    @RequestMapping("/test/stu.json")
    public ResultEntity<Student> testJson(@RequestBody Student student,HttpServletRequest httpServletRequest){
        boolean judgeResult = CrowdUtil.judgeRequestType(httpServletRequest);
        System.out.println(judgeResult);
        return ResultEntity.successWithData(student);
    }

}
